package com.zsc.tool;

/**
 * Created by xbkaishui on 17/3/7.
 */
public class RedisConnection {

    private String host;
    private int port;
    private String password;

    private RedisConnection(){}

    private RedisConnection(Builder builder) {
        this.host = builder.host;
        this.password = builder.password;
        this.port = builder.port;
    }

    public String getPassword() {
        return password;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    static class Builder {
        String host;
        int port;
        //optional
        String password;

        public  Builder(String host, int port) {
            this.host = host;
            this.port = port;
        }

        public Builder withPassWord(String pwd) {
            this.password = pwd;
            return this;
        }

        public RedisConnection build() {
            return new RedisConnection(this);
        }
    }

    @Override public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        RedisConnection that = (RedisConnection) o;

        if (port != that.port)
            return false;
        return host != null ? host.equals(that.host) : that.host == null;

    }

    @Override public int hashCode() {
        int result = host != null ? host.hashCode() : 0;
        result = 31 * result + port;
        return result;
    }
}
